
package com.tools.cleanmaster.ui.card;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;

import com.tools.ad.EntranceType;
import com.tools.ad.util.GARecordUtils;
import com.tools.cleanmaster.CleanGAConstant;
import com.tools.cleanmaster.R;
import com.tools.cleanmaster.functionpage.FunctionItem;
import com.tools.cleanmaster.functionpage.FunctionItemSharedPrefs;
import com.tools.cleanmaster.ui.activity.FunctionPageGuideActivity;
import com.tools.cleanmaster.ui.card.factory.CardListAdapter;
import com.tools.cleanmaster.ui.card.viewholder.ACardViewHolder;
import com.tools.cleanmaster.ui.card.viewholder.FuncCardViewHolder;

/**
 * desc: 首页 手机降温 功能卡片
 * date: 2018/6/25 18:04
 * author: ancun
 */
public class FuncCoolerItem extends ACardItem {

    private FuncCardViewHolder mCardViewHolder;

    public FuncCoolerItem(EntranceType entranceType, int pos) {
        super(entranceType, pos);
    }

    @Override
    public CardViewType getCardViewType() {
        return CardViewType.COOLER;
    }

    @Override
    public boolean needShow(EntranceType entranceType) {
        return true;
    }

    @Override
    public void bindCardView(final Activity activity, ACardViewHolder viewHolder, CardListAdapter cardAdapter, final int position) {
        super.bindCardView(activity, viewHolder, cardAdapter, position);
        mCardViewHolder = (FuncCardViewHolder) viewHolder;

        mCardViewHolder.mLogo.setImageResource(R.drawable.card_func_cooler);
        mCardViewHolder.mTitle.setText(activity.getString(R.string.function_cpucool_icon_text));
        mCardViewHolder.mDesc.setText(activity.getString(R.string.function_cpucool_icon_desc));
        mCardViewHolder.mExecute.setText(R.string.battery_low_btn);

        mCardViewHolder.mExecute.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                doClick(activity, position);
            }
        });
        mCardViewHolder.mItemView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                doClick(activity, position);
            }
        });
    }

    @Override
    public String getCardName() {
        return CardType.COOLER.key;
    }

    private void doClick(Activity activity, int position) {
        FunctionItem item = FunctionItemSharedPrefs.getIsCpuNormal(imContext) ? FunctionItem.CPUCOOL : FunctionItem.CPUOVER;
        Intent intent = new Intent(activity, FunctionPageGuideActivity.class);
        intent.putExtra(FunctionPageGuideActivity.ITEM_EXTEA_FLAG, item.toString());
        activity.startActivity(intent);

        GARecordUtils.report(imContext, CleanGAConstant.C_FUNC, CleanGAConstant.A_CLICK,
                CleanGAConstant.L_CARD_COOLER);

        if (mCardViewHolder.mPageEntrance == EntranceType.HOME_TRASH_COMPLETED) {
            imContext.handleMobEmptyDelayMessage(R.id.msg_show_first_page_scan, 1000L);
        }
    }
}
